sugarfreeControllers.controller('ChangePWDCtrl',['$scope','$modalInstance','items','HttpService',function($scope,$modalInstance,items,httpService){
	  $scope.items = items;
	  console.info("$scope.items",$scope.items);
	  $scope.selected = {
	    //item: $scope.items[0]
	  };
	  $scope.ok = function () {
	  	$scope.user = $scope.user || {};
	  	var oldPassword = $scope.user.oldPassword;
	  	var newPassword = $scope.user.newPassword;
	  	var reNewPassword = $scope.user.reNewPassword;
	  	
	  	var valid = true;
	  	$scope.errMsg = $scope.errMsg || {};
	  	if(!oldPassword){
	  		$scope.errMsg.emptyOldPassword = $scope.msg.emptyOldPassword;
	  		valid = false;
	  	}else{
	  		$scope.errMsg.emptyOldPassword = '';
	  	}
	  	
	  	if(!newPassword){
	  		$scope.errMsg.emptyNewPassword = $scope.msg.emptyNewPassword;
	  		valid = false;
	  	}else{
	  		$scope.errMsg.emptyNewPassword = '';
	  	}
	  	
	  	if(!reNewPassword){
	  		$scope.errMsg.emptyReNewPassword = $scope.msg.emptyReNewPassword;
	  		valid = false;
	  	}else{
	  		$scope.errMsg.emptyReNewPassword = '';
	  	}
	  	if(valid && oldPassword === newPassword){
	  		$scope.errMsg.oldAndNewPasswordIdentical = $scope.msg.oldAndNewPasswordIdentical;
	  		valid = false;
	  	}else{
	  		$scope.errMsg.oldAndNewPasswordIdentical = '';
	  	}
	  	
	  	if(valid && newPassword !== reNewPassword){
	  		$scope.errMsg.passwordInequality = $scope.msg.passwordInequality;
	  		valid = false;
	  	}else{
	  		$scope.errMsg.passwordInequality = '';
	  	}
	  	if(valid){
	  		var _dataStr = "oldPassword=" + oldPassword  +
	  								   "&newPassword=" + newPassword +
	  								   "&reNewPassword=" + reNewPassword;
	  		console.info("_dataStr",_dataStr);
	  		httpService.post('change/password',_dataStr)
	  							 .then(function(rsps){
	  							 	if(rsps.data.errCode === '8000'){
	  							 		alert('密码修改成功');
	  							 		$modalInstance.close();
	  							 	}else if(rsps.data.errCode=== '8112'){
	  							 		alert('密码修改失败，旧密码不正确');
	  							 	}else if(rsps.data.errCode === '8601'){
	  							 		alert('密码修改失败，新密码与旧密码不能相同');
	  							 	}else if(rsps.data.errCode === '8602'){
	  							 		alert('密码修改失败，两次输入的新密码不一致');
	  							 	}
	  							 },function(rsps){
	  							 	alert('密码修改出错');
	  							 	$modalInstance.close();
	  							 });
	  	}
	  };
	
	  $scope.cancel = function () {
	    $modalInstance.dismiss('cancel');
	  };
	  
	  
	  	  
	  $scope.msg={
	  	emptyOldPassword : "旧密码不能为空",
	  	emptyNewPassword : "新密码不能为空",
	  	emptyReNewPassword : "请再次输入新密码",
	  	oldAndNewPasswordIdentical:'新密码与旧密码不能相同',
	  	passwordInequality:'两次输入的新密码不一致，请重新输入'
	  };
}]);
